<template>
  <div class="app-container">
    <div class="filter-container">
      <el-card>
        <el-form ref="searchform" :inline="true" :model="searchform" class="demo-form-inline" size="small">
          <el-form-item label="商品名称：">
            <el-input v-model="searchform.Keywords" clearable placeholder="商品名称" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <el-card>
      <div class="list-btn-container">
        <el-button-group>
          <slot v-for="itemf in loadBtnFunc">
            <el-button v-if="itemf.FullName==='新增'" type="default" icon="el-icon-plus" size="small" @click="ShowEditOrViewDialog()">新增</el-button>
            <el-button v-if="itemf.FullName==='修改'" type="default" icon="el-icon-edit" size="small" @click="ShowEditOrViewDialog('edit')">修改</el-button>
            <el-button v-if="itemf.FullName=='下架'" type="default" icon="el-icon-video-pause" size="small" @click="SetOnState('2')">下架</el-button>
            <el-button v-if="itemf.FullName=='上架'" type="default" icon="el-icon-video-play" size="small" @click="SetOnState('1')">上架</el-button>
            <el-button v-if="itemf.FullName==='软删除'" type="default" icon="el-icon-delete" size="small" @click="deleteSoft('0')">软删除</el-button>
            <el-button v-if="itemf.FullName==='删除'" type="default" icon="el-icon-delete" size="small" @click="deletePhysics()">删除</el-button>
            <el-button v-if="itemf.FullName==='重置密码'" type="default" icon="el-icon-refresh-right" size="small" @click="handleResetPassword()">重置密码</el-button>
          </slot>
          <el-button type="default" icon="el-icon-refresh" size="small" @click="loadTableData()">刷新</el-button>
        </el-button-group>
      </div>
      <el-table
        ref="gridtable"
        v-loading="tableloading"
        :data="tableData"
        border
        stripe
        highlight-current-row
        style="width: 100%"
        :default-sort="{prop: 'SortCode', order: 'descending'}"
        @select="handleSelectChange"
        @select-all="handleSelectAllChange"
        @sort-change="handleSortChange"
      >
        <el-table-column
          type="selection"
          width="30"
        />
        <el-table-column
          prop="Id"
          label="编号"
          sortable="custom"
          width="230"
          align="center"
        />
        <el-table-column
          prop="Title"
          label="名称"
          sortable="custom"
          width="230"
          align="center"
        />
        <el-table-column
          prop="GoodsCategoryDto.Title"
          label="分类"
          sortable="custom"
          width="180"
          align="center"
        />
        <el-table-column
          prop="MarketPrice"
          label="市场价"
          sortable="custom"
          width="190"
          align="center"
        />
        <el-table-column
          prop="Price"
          label="价格"
          sortable="custom"
          width="190"
          align="center"
        />
        <el-table-column
          prop="Stock"
          label="库存"
          sortable="custom"
          width="190"
          align="center"
        />
        <el-table-column
          prop="TypeDes"
          label="类型"
          sortable="custom"
          width="190"
          align="center"
        />
        <el-table-column
          label="返利"
          sortable="custom"
          width="90"
          prop="IsRebate"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.IsRebate === true ? 'success' : 'info'"
              disable-transitions
            >{{ scope.row.IsRebate===true?'是':'否' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="Sort"
          label="排序"
          sortable="custom"
          width="190"
          align="center"
        />
        <el-table-column
          label="状态"
          sortable="custom"
          width="90"
          prop="OnState"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.OnState === 1 ? 'success' : 'info'"
              disable-transitions
            >{{ scope.row.OnState===1?'上架':scope.row.OnState===0?'新增':'下架' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="CreateTime"
          label="添加时间"
          width="180"
          sortable
        />
        <el-table-column
          prop="LastModifyTime"
          label="修改时间"
          width="180"
          sortable
        />

        <el-table-column
          fixed="right"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="ShowEditOrViewDialog('select',scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          background
          :current-page="pagination.currentPage"
          :page-sizes="[5,10,20,50,100, 200, 300, 400]"
          :page-size="pagination.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.pageTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
    <el-dialog ref="dialogEditForm" :title="editFormTitle+'商品'" :visible.sync="dialogEditFormVisible" width="1200px">
      <el-form ref="editFrom" :model="editFrom" :rules="rules">
        <el-tabs v-model="activeName" type="border-card">
          <el-tab-pane label="基本信息" name="first">
            <el-form-item label="商品分类" :label-width="formLabelWidth" prop="CategoryId">
              <el-select v-model="editFrom.CategoryId" :disabled="IsDisabled" clearable placeholder="请选择商品分类" style="width:390px;">
                <el-option
                  v-for="item in selectCategoryOptions"
                  :key="item.Id"
                  :label="item.Title"
                  :value="item.Id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="类型" :label-width="formLabelWidth" prop="Type">
              <el-select v-model="editFrom.Type" clearable placeholder="请选择类型" :disabled="IsDisabled" style="width:390px;" @change="selecetTypeChange">
                <el-option
                  v-for="item in selectTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="优惠劵" :label-width="formLabelWidth" prop="CouponId">
              <el-select v-model="editFrom.CouponId" :disabled="IsDisabled" clearable placeholder="选择下单发放优惠劵" style="width:390px;">
                <el-option
                  v-for="item in CouponOptions"
                  :key="item.Id"
                  :label="item.Title"
                  :value="item.Id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="名称" :label-width="formLabelWidth" prop="Title">
              <el-input v-model="editFrom.Title" :disabled="IsDisabled" placeholder="请输入名称" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="子名称" :label-width="formLabelWidth" prop="Subtitle">
              <el-input v-model="editFrom.Subtitle" :disabled="IsDisabled" placeholder="请输入子名称" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="市场价" :label-width="formLabelWidth" prop="MarketPrice">
              <el-input v-model="editFrom.MarketPrice" :disabled="IsDisabled" placeholder="请输入市场价" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="价格" :label-width="formLabelWidth" prop="Price">
              <el-input v-model="editFrom.Price" :disabled="IsDisabled" placeholder="请输入价格" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="库存" :label-width="formLabelWidth" prop="Stock">
              <el-input v-model="editFrom.Stock" :disabled="IsDisabled" placeholder="请输入库存" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="排序" :label-width="formLabelWidth" prop="Sort">
              <el-input-number v-model="editFrom.Sort" :min="1" placeholder="请输入排序序号" style="width:390px;" />
            </el-form-item>
            <el-form-item label="虚拟销量" :label-width="formLabelWidth" prop="VirtualSaleNun">
              <el-input-number v-model="editFrom.VirtualSaleNun" :min="0" placeholder="请输入虚拟销量" style="width:390px;" />
            </el-form-item>
            <el-form-item label="是否允许返利" :label-width="formLabelWidth" prop="IsRebate">
              <el-checkbox v-model="editFrom.IsRebate" />
            </el-form-item>
            <el-form-item label="封面" :label-width="formLabelWidth" prop="HeadUpload">
              <ele-upload-image
                v-model="editFrom.CoverImageUrl"
                :file-size="5"
                :is-show-tip="false"
                :lazy="true"
                :response-fn="handleResponse"
                :action="httpFileUploadUrl"
                title="封面"
              />
            </el-form-item>

            <el-form-item label="图片" :label-width="formLabelWidth" :disabled="IsDisabled" prop="GoodsImages">
              <el-upload
                :action="httpFileUploadUrl"
                list-type="picture-card"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove"
                :limit="8"
                :disabled="IsDisabled"
                :file-list="filelist"
                :on-success="uploadFileSuccess"
              >
                <i class="el-icon-plus" />
              </el-upload>
              <el-dialog :visible.sync="dialogHeadIconVisible">
                <img width="100%" :src="dialogHeadIconImageUrl" alt="">
              </el-dialog>
            </el-form-item></el-form-item></el-tab-pane>
          <el-tab-pane label="商品描述" name="second">
            <el-form-item label="" prop="content">
              <!-- <quill-editor ref="text" v-model="content" :disabled="IsDisabled" style="height: 500px;" class="myQuillEditor" :options="editorOption" /> -->
              <editor v-model="content" :is-clear="isClear" :disabled="IsDisabled" style="width:1100px;" @change="change" />
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="规格" name="three">
            <el-form-item label="规格名称" :label-width="formLabelWidth" prop="SpecName">
              <el-input v-model="editFrom.SpecName" style="width: 200px;" placeholder="请输入规格名称" :disabled="IsDisabled" autocomplete="off" clearable />
            </el-form-item>
            <el-form-item v-for="(item,index) in editFrom.GoodsSpecRequests">
              <el-col :span="5">
                <el-form-item label="名称" :label-width="formLabelWidth" :prop="'GoodsSpecRequests.'+index+'.Name'" :rules="GoodsSpecRequestsRules.GoodsSpecRequestsName" style="width: 500px;">
                  <el-input v-model="item.Name" placeholder="请输入名称" :disabled="IsDisabled" autocomplete="off" clearable style="width: 170px;" @input="onInput()" />
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="价格" :label-width="formLabelWidth" :prop="'GoodsSpecRequests.'+index+'.Price'" :rules="GoodsSpecRequestsRules.GoodsSpecRequestsPrice" style="width: 500px;">
                  <el-input v-model="item.Price" placeholder="请输入价格" :disabled="IsDisabled" autocomplete="off" clearable style="width: 170px;" @input="onInput()" />
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="库存" :label-width="formLabelWidth" :prop="'GoodsSpecRequests.'+index+'.Stock'" :rules="GoodsSpecRequestsRules.GoodsSpecRequestsStock" style="width: 500px;">
                  <el-input v-model="item.Stock" placeholder="请输入库存" :disabled="IsDisabled" autocomplete="off" clearable style="width: 200px;" @input="onInput()" />
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item v-show="index===0" style="width: 50px;" :label-width="formLabelWidth">
                  <el-button type="success" :disabled="IsDisabled" icon="el-icon-circle-plus" @click="addOrderSpec" /></el-form-item>
                <el-form-item v-show="index!==0" style="width: 50px;" :label-width="formLabelWidth">
                  <el-button type="danger" :disabled="IsDisabled" icon="el-icon-remove" @click="delOrderSpec(index)" /></el-form-item>
              </el-col>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="推广" name="four">
            <el-form-item label="优惠劵" :label-width="formLabelWidth" prop="CouponId">
              <el-select v-model="editFrom.GoodsPromotionRequest.RebateCouponId" :disabled="IsDisabled" clearable placeholder="选择下单发放优惠劵" style="width:390px;">
                <el-option
                  v-for="item in CouponOptions"
                  :key="item.Id"
                  :label="item.Title"
                  :value="item.Id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="返利金额" :label-width="formLabelWidth" prop="Price">
              <el-input v-model="editFrom.GoodsPromotionRequest.CashbackAmount" :disabled="IsDisabled" placeholder="请输入价格" autocomplete="off" clearable style="width:390px;" />
            </el-form-item>
            <el-form-item label="是否启动" :label-width="formLabelWidth" prop="IsRebate">
              <el-checkbox v-model="editFrom.GoodsPromotionRequest.IsEnable" />
            </el-form-item>

          </el-tab-pane>
          <!-- <el-tab-pane v-if="isShowDoctor" label="皮肤管理师" name="four">
            <template>
              <el-table
                :data="doctors"
                style="width: 100%"
              >
                <el-table-column
                  prop="Name"
                  label="姓名"
                  width="180"
                />
                <el-table-column
                  prop="JobTitle"
                  label="职称"
                  width="180"
                />
                <el-table-column
                  prop="Introduce"
                  label="简介"
                  width="440"
                />
                <el-table-column
                  fixed="right"
                  label="操作"
                >
                  <template slot-scope="scope">
                    <el-button v-show="scope.row.Select==false" :disabled="IsDisabled" @click="selectDoctor(scope.row)">选择</el-button>
                    <el-button v-show="scope.row.Select==true" :disabled="IsDisabled" type="primary" @click="cancelDoctor(scope.row)">选择</el-button>
                  </template>
                </el-table-column>

              </el-table>

            </template>
          </el-tab-pane> -->
        </el-tabs>
        </el-tabs></el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogEditFormVisible = false">取 消</el-button>
        <el-button :disabled="IsDisabled" type="primary" @click="saveEditForm()">保 存</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>

import { getPage, save, getDetail, del, SetOnState, delSoft, GetAllCouponEnable } from '@/api/shop/goodsservice'
import { GetAllEnable } from '@/api/shop/goodscategoryservice'
import { GetDoctorAllEnable } from '@/api/shop/doctorservice'
import defaultSettings from '@/settings'
import * as fecha from 'element-ui/lib/utils/date'
import EleUploadImage from '@/components/upload/EleUploadImage'
import editor from '@/components/Editor/editor'
export default {
  components: {
    editor,
    EleUploadImage
  },
  data() {
    return {
      activeName: 'first',
      IsDisabled: false,
      isClear: false,
      content: '',
      searchform: {
        Keywords: '',
        BrandId: '',
        CategoryId: '',
        Type: '',
        GoodsOnState: null,
        GoodsSortByEnum: null
      },

      selectRole: [],
      selectCategoryOptions: [],
      doctors: [],
      CouponOptions: [],
      selectTypeOptions: [{
        value: 1,
        label: '人气榜单'
      }, {
        value: 2,
        label: '黑标产品'
      },
      {
        value: 3,
        label: '门槛礼包'
      }],
      selectOrganize: [],
      GoodsImages: '',
      loadBtnFunc: [],
      tableData: [],
      tableloading: true,
      pagination: {
        currentPage: 1,
        pagesize: 10,
        pageTotal: 0
      },
      sortableData: {
        // order: '',
        // sort: ''
      },
      dialogEditFormVisible: false,
      editFormTitle: '',
      editFrom: {
        Id: '',
        Title: '',
        BrandId: 0,
        CategoryId: null,
        OnState: 0,
        Price: 0,
        Subtitle: '',
        MarketPrice: 0,
        Stock: 1,
        Detail: '',
        EnabledMark: true,
        Type: null,
        GoodsSpecRequests: [{ GoodsId: null, Name: '', Price: 0, Stock: 0 }],
        GoodsFileRequests: [],
        GoodsDoctorRequests: [{ DoctorId: null }],
        GoodsPromotionRequest: {},
        CoverImageUrl: '',
        SpecName: '规格',
        Sort: 99,
        VirtualSaleNun: 0,
        CouponId: '',
        IsRebate: true
      },
      rules: {
        CategoryId: [
          { required: true, message: '请选择分类', trigger: 'blur' }
        ],
        Title: [
          { required: true, message: '请输入商品名称', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        Subtitle: [
          { required: true, message: '请输入商品负名称', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        MarketPrice: [
          { required: true, message: '请输入市场价格', trigger: 'blur' }
        ],
        Type: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
        Stock: [
          { required: true, message: '请输入库存', trigger: 'blur' }
        ],
        Price: [
          { required: true, message: '请输入价格', trigger: 'blur' }
        ],
        itemName: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        itemStock: [
          { required: true, message: '请输入库存', trigger: 'blur' }
        ],
        itemPrice: [
          { required: true, message: '请输入价格', trigger: 'blur' }
        ],
        SpecName: [
          { required: true, message: '请输入规格名称', trigger: 'blur' }
        ],
        Sort: [
          { required: true, message: '请输入排序', trigger: 'blur' }
        ]
      },
      GoodsSpecRequestsRules: {
        GoodsSpecRequestsName: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        GoodsSpecRequestsPrice: [
          { required: true, message: '请输入价格', trigger: 'blur' }
        ],
        GoodsSpecRequestsStock: [
          { required: true, message: '请输入库存', trigger: 'blur' }
        ]
      },
      httpFileUploadUrl: defaultSettings.fileUploadUrl,
      dialogVisible: false,
      isShowDoctor: false,
      dialogImageUrl: '',
      filelist: [],
      dialogHeadIconVisible: false,
      dialogHeadIconImageUrl: '',
      formLabelWidth: '150px',
      currentId: '',
      currentSelected: []
    }
  },
  created() {
    this.pagination.currentPage = 1
    this.InitDictItem()
    this.loadTableData()
    this.loadBtnFunc = JSON.parse(localStorage.getItem('yueboncurrentfuns'))
  },
  methods: {

    InitDictItem() {
      GetAllEnable().then(res => {
        this.selectCategoryOptions = res.ResData
      })
      GetAllCouponEnable().then(res => {
        this.CouponOptions = res.ResData
      })
      GetDoctorAllEnable().then(res => {
        this.doctors = res.ResData
      })
    },
    change(val) {
      console.log(val)
    },
    selecetTypeChange: function(value) {
      if (value === 2) {
        // this.isShowDoctor = true
      } else {
        // this.isShowDoctor = false
      }
    },
    selectDoctor: function(item) {
      item.Select = true
      this.editFrom.GoodsDoctorRequests.push({ DoctorId: item.Id })
    },
    cancelDoctor: function(item) {
      item.Select = false
      // 移除doctor
      var index = this.list.findIndex(s => {
        if (s.DoctorId === item.DoctorId) {
          return true
        }
      })
      this.list.splice(index, 1)
    },
    loadTableData: function() {
      this.tableloading = true
      var seachdata = {
        'CurrenetPageIndex': this.pagination.currentPage,
        'PageSize': this.pagination.pagesize,
        'Keywords': this.searchform.Keywords,
        'CategoryId': '',
        'Type': null,
        'GoodsOnState': null
      }
      getPage(seachdata).then(res => {
        this.tableData = res.ResData.Items
        this.pagination.pageTotal = res.ResData.TotalItems
        this.tableloading = false
      })
    },
    addOrderSpec: function() {
      this.editFrom.GoodsSpecRequests.push({ GoodsId: null, Name: '', Price: null, Stock: null })
    },
    delOrderSpec: function(index) {
      this.editFrom.GoodsSpecRequests.splice(index, 1)
    },
    handleSearch: function() {
      this.pagination.currentPage = 1
      this.loadTableData()
    },
    handleRemove(file, fileList) {
      console.log(file)
      this.editFrom.GoodsImages = file.url
      this.editFrom.GoodsFileRequests = this.editFrom.GoodsFileRequests.filter(s => s.Desc !== file.name)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    ShowEditOrViewDialog: function(view, row) {
      if (row != null && row !== undefined) {
        this.currentId = row.Id
      } else {
        if (this.currentSelected !== '' && this.currentSelected.length > 0 && this.currentSelected[0].Id >= 0) {
          this.currentId = this.currentSelected[0].Id
        }
      }
      if (view !== undefined) {
        if (view === 'select') {
          this.editFormTitle = '查看'
          this.IsDisabled = true
          this.dialogEditFormVisible = true
          this.bindEditInfo()
        } else {
          if ((this.currentId.length < 0 || this.currentId.length === 0)) {
            this.$alert('请选择一条数据进行编辑/修改', '提示')
            return false
          }
          this.editFormTitle = '编辑'
          this.dialogEditFormVisible = true
          this.IsDisabled = false
          this.bindEditInfo()
        }
      } else {
        this.editFormTitle = '新增'
        this.IsDisabled = false
        this.currentId = ''
        this.selectedOrganizeOptions = ''
        this.dialogEditFormVisible = true
        this.editFrom.CoverImageUrl = ''
        this.filelist = []
        this.editFrom.GoodsSpecRequests = [{ GoodsId: null, Name: '', Price: 0, Stock: 0 }]
        this.editFrom.GoodsPromotionRequest = {}
        this.content = ''
        this.editFrom.Type = 1
        this.$nextTick(function() {
          this.$refs['editFrom'].resetFields()
        })
      }
    },
    bindEditInfo: function() {
      getDetail(this.currentId).then(res => {
        this.editFrom.Title = res.ResData.Title
        this.editFrom.BrandId = res.ResData.BrandId
        this.editFrom.CategoryId = res.ResData.CategoryId
        this.editFrom.OnState = res.ResData.OnState
        this.editFrom.Price = res.ResData.Price
        this.editFrom.Subtitle = res.ResData.Subtitle
        this.editFrom.CouponId = res.ResData.CouponId
        this.editFrom.MarketPrice = res.ResData.MarketPrice
        this.editFrom.Stock = res.ResData.Stock
        this.editFrom.Detail = res.ResData.Detail
        this.editFrom.Type = res.ResData.Type
        this.editFrom.Sort = res.ResData.Sort
        this.editFrom.VirtualSaleNun = res.ResData.VirtualSaleNun
        this.editFrom.SpecName = res.ResData.SpecName
        this.editFrom.EnabledMark = res.ResData.EnabledMark
        this.editFrom.GoodsSpecRequests = res.ResData.GoodsSpecDtos
        this.editFrom.IsRebate = res.ResData.IsRebate
        this.editFrom.GoodsPromotionRequest = res.ResData.GoodsPromotionDto != null ? res.ResData.GoodsPromotionDto : { }
        this.editFrom.GoodsFileRequests = res.ResData.GoodsFileDtos != null ? res.ResData.GoodsFileDtos : []
        this.filelist = []
        res.ResData.GoodsFileDtos.forEach(s => {
          if (s.IsCover === true) {
            this.editFrom.CoverImageUrl = s.FilePath
          } else {
            this.filelist.push({ name: s.Desc, url: s.FilePath })
          }
        })
        this.editFrom.GoodsDoctorRequests = res.ResData.GoodsDoctorDtos != null ? res.ResData.GoodsDoctorDtos : []
        this.editFrom.Id = res.ResData.Id
        this.content = res.ResData.Detail
        this.editFrom.DeleteMark = res.ResData.DeleteMark
      })
    },
    /**
     * 新增/修改保存
     */
    saveEditForm() {
      console.log(this.editFrom.RoleId)
      this.$refs['editFrom'].validate((valid) => {
        if (valid) {
          const data = {
            Title: this.editFrom.Title,
            BrandId: this.editFrom.BrandId,
            CategoryId: this.editFrom.CategoryId,
            OnState: this.editFrom.OnState,
            Price: this.editFrom.Price,
            Subtitle: this.editFrom.Subtitle,
            MarketPrice: this.editFrom.MarketPrice,
            Stock: this.editFrom.Stock,
            Detail: this.content,
            Sort: this.editFrom.Sort,
            CouponId: this.editFrom.CouponId,
            VirtualSaleNun: this.editFrom.VirtualSaleNun,
            EnabledMark: this.editFrom.EnabledMark,
            DeleteMark: this.editFrom.DeleteMark,
            Type: this.editFrom.Type,
            SpecName: this.editFrom.SpecName,
            IsRebate: this.editFrom.IsRebate,
            'Id': this.currentId,
            GoodsSpecRequests: this.editFrom.GoodsSpecRequests,
            GoodsFileRequests: this.editFrom.GoodsFileRequests,
            GoodsDoctorRequests: this.editFrom.GoodsDoctorRequests,
            GoodsPromotionRequest: this.editFrom.GoodsPromotionRequest
          }

          var url = 'goods/create'
          if (this.currentId !== '') {
            url = 'goods/updateAsync'
          }
          save(data, url).then(res => {
            if (res.Success) {
              this.$message({
                message: '恭喜你，操作成功',
                type: 'success'
              })
              this.dialogEditFormVisible = false
              this.currentSelected = ''
              this.selectedOrganizeOptions = ''
              this.$nextTick(function() {
                this.$refs['editFrom'].resetFields()
              })
              this.loadTableData()
              this.InitDictItem()
            } else {
              this.$message({
                message: res.ErrMsg,
                type: 'error'
              })
            }
          })
        } else {
          this.$message.error('你有未填写的数据,请检查')
        }
      })
    },
    SetOnState: function(val) {
      if (this.currentSelected.length === 0) {
        this.$alert('请先选择要操作的数据', '提示')
        return false
      } else {
        var currentIds = ''
        this.currentSelected.forEach(element => {
          currentIds += element.Id + ','
        })
        const data = {
          ids: currentIds,
          bltag: val
        }
        SetOnState(data).then(res => {
          if (res.Success) {
            this.$message({
              message: '恭喜你，操作成功',
              type: 'success'
            })
            this.currentSelected = ''
            this.loadTableData()
          } else {
            this.$message({
              message: res.ErrMsg,
              type: 'error'
            })
          }
        })
      }
    },
    deleteSoft: function(val) {
      if (this.currentSelected.length === 0) {
        this.$alert('请先选择要操作的数据', '提示')
        return false
      } else {
        var currentIds = ''
        this.currentSelected.forEach(element => {
          currentIds += element.Id + ','
        })
        const data = {
          ids: currentIds,
          bltag: val
        }
        delSoft(data).then(res => {
          if (res.Success) {
            this.$message({
              message: '恭喜你，操作成功',
              type: 'success'
            })
            this.currentSelected = ''
            this.loadTableData()
          } else {
            this.$message({
              message: res.ErrMsg,
              type: 'error'
            })
          }
        })
      }
    },
    deletePhysics: function() {
      if (this.currentSelected.length === 0) {
        this.$alert('请先选择要操作的数据', '提示')
        return false
      } else {
        var currentIds = ''
        this.currentSelected.forEach(element => {
          currentIds += element.Id + ','
        })
        const data = {
          ids: currentIds
        }
        del(data).then(res => {
          if (res.Success) {
            this.$message({
              message: '恭喜你，操作成功',
              type: 'success'
            })
            this.currentSelected = ''
            this.loadTableData()
          } else {
            this.$message({
              message: res.ErrMsg,
              type: 'error'
            })
          }
        })
      }
    },
    /**
     * 当表格的排序条件发生变化的时候会触发该事件
     */
    handleSortChange: function(column) {
      this.sortableData.sort = column.prop
      if (column.order === 'ascending') {
        this.sortableData.order = 'asc'
      } else {
        this.sortableData.order = 'desc'
      }
      this.loadTableData()
    },
    /**
     * 当用户手动勾选checkbox数据行事件
     */
    handleSelectChange: function(selection, row) {
      this.currentSelected = selection
    },
    /**
     * 当用户手动勾选全选checkbox事件
     */
    handleSelectAllChange: function(selection) {
      this.currentSelected = selection
    },
    /**
     * 选择每页显示数量
     */
    handleSizeChange(val) {
      this.pagination.pagesize = val
      this.pagination.currentPage = 1
      this.loadTableData()
    },
    /**
     * 选择当页面
     */
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.loadTableData()
    },
    dateformatter(row, column, cellValue, index) {
      var date = row[column.property]
      return cellValue ? fecha.format(new Date(date), 'yyyy-MM-dd') : ''
    },
    uploadFileSuccess: function(response, file, fileList) {
      console.log(file)
      this.editFrom.FilePath = defaultSettings.fileUrl + response.ResData.FilePath
      this.editFrom.GoodsFileRequests.push({ UploadfileId: response.ResData.Id, Type: 1, Desc: response.ResData.FileName, IsCover: false })
    },
    handleResponse(response, file, fileList) {
      this.editFrom.CoverImageUrl = defaultSettings.fileUrl + response.ResData.FilePath
      this.editFrom.GoodsFileRequests = this.editFrom.GoodsFileRequests.filter(s => s.IsCover === false)
      this.editFrom.GoodsFileRequests.push({ UploadfileId: response.ResData.Id, Type: 1, Desc: response.ResData.FileName, IsCover: true })
      return file.url
    },
    onInput() {
      this.$forceUpdate()
    }
  }
}
</script>
